<template>
	<view class="container">
		<navSearchBar title="我的分享"></navSearchBar>
		<view class="content">
			<my-tab-list :tab="tab" :current="current" :list="list" @currentTab="currentTab"  @toDetail="toDetail" @loadMore="loadMore"></my-tab-list>
		</view>
	</view>
</template>

<script>
	import myTabList from "@/components/my-componets/my-tab-list.vue"
	export default {
		components: {
			myTabList
		},
		data() {
			return {
				tab: [
					{name:"产品",fun:"productShare",url:"productDetail"},
					{name:"案例",fun:"caseShare",url:"sampleDetail"},
					{name:"基地",fun:"baseShare",url:"baseResourceDetail"},
					{name:"讲师",fun:"lecturerShare",url:"teacherResourceDetail"},
					{name:"供应商",fun:"supplierShare",url:"supplierResourceDeatil"},
				],
				current:0,
				list:[],
				page:1,
				pageSize:10
			};
		},
		onLoad() {
			this.getShare()
		},
		methods:{
			async getShare() {
				console.log(this.tab[this.current].fun)
				uni.showLoading({
					title: '加载中'
				})
				let res = await this.$api[this.tab[this.current].fun]({limit:this.page * this.pageSize})
				if(res.data.status) {
					uni.hideLoading();
					this.list = res.data.data.data
				}
			},
			loadMore() {
				if(this.list.length <= this.page * this.pageSize) return
				this.page++
				this.getShare()
			},
			currentTab(num) {
				this.current = num
				this.page = 1
				this.getShare()
			},
			toDetail(info) {
				console.log('bbbbbbb',this.tab[this.current].url)
				this.$Router.push({name:'productDetail',query:{id:info.relevance.id}})
			} 
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}
	
	.content {
		flex: 1;
		overflow: hidden;
	}
</style>